#include <bits/stdc++.h>
using namespace std;
double L, a, b;
double gas(int A){
    int gas_per = 2000+10*abs(A-30);
    double V = 400.0 + (b-a)/20.0*A - b +2*a;
    double up = 50*A, fly = L/V*gas_per;
    return up + fly;
}

int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    int T; cin >> T;
    int cnt = 0;
    while(++cnt <=T){
        cout << "Flight " << cnt << ":";
        int N; cin >> N;
        vector<int> best;
        double total = 0;
        for (int i = 0; i < N; ++i) {
            cin >> L >> a >> b;
            double g = DBL_MAX; int best_A = -1;
            for (int A = 20; A <= 40; ++A) {
                double t = gas(A);
                if(t<g){
                    g = t;
                    best_A = A;
                }
            }
            total += g;
            best.push_back(best_A);
        }
        for (auto &i:best) cout << " " << i;
        cout <<  " " <<  ceil(total) << "\n";
    }
    return 0;
}